﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Model;
using Resources;
using Service;

public partial class EquipmentTypeAdd : System.Web.UI.Page
{
    readonly ReferenceDataService _ReferenceDataService = new ReferenceDataService();
    readonly StockService _StockService = new StockService();
    private DirectService _DirectService = new DirectService();

    
    
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void bntValidate_Click(object sender, EventArgs e)
    {
        EquipmentType _equipmentType = new EquipmentType();
         if(string.IsNullOrEmpty(txtEquipmentType.Text))
         {
             lblRequiredEquipmentType.Visible = true;
             lblRequiredUnit.Visible = false;
             lblMessageValidate.Text = "";
             return;
         }
         if(string.IsNullOrEmpty(txtUnit.Text ))
         {
             lblRequiredUnit.Visible = true;
             lblRequiredEquipmentType.Visible = false;
             lblMessageValidate.Text = ""; 
             return;
         }

          lblRequiredEquipmentType.Visible = false;
            lblRequiredUnit.Visible = false; 
            _equipmentType.EquipmentTypeId = 0;
            _equipmentType.EquipmentTypeLabel = txtEquipmentType.Text;
            _equipmentType.Unit = txtUnit.Text;
            if (chbSparePart.Checked) _equipmentType.IsSparePart = true;
            else _equipmentType.IsSparePart = false;

            if (chbBuiltIn.Checked) _equipmentType.IsBuiltIn = true;
            else _equipmentType.IsBuiltIn = false;
            int i;
            if (!string.IsNullOrEmpty(txtMinimum.Text))
            {
                if (int.TryParse(txtMinimum.Text, out i))
                {
                    _equipmentType.MinimumInStock = i;
                }
            }
            int j;
            if (!string.IsNullOrEmpty(txtMinimum.Text))
            {
                if (int.TryParse(txtMinimum.Text, out j))
                {
                    _equipmentType.MaximumInStock = j;
                }
            }

            _ReferenceDataService.SaveEquipmentType(_equipmentType);
            CelarControlAdd();
            lblMessageValidate.Text = Resource.MessageValidate; 
                 
    }
    private void CelarControlAdd()
    {
        txtEquipmentType.Text = "";
        txtMaximum.Text = "";
        txtMinimum.Text = "";
        txtUnit.Text = "";
        chbSparePart.Checked = false;
        chbBuiltIn.Checked = false;
        lblRequiredEquipmentType.Visible = false;
        lblRequiredUnit.Visible = false;
        lblMessageValidate.Text = ""; 
    }
    protected void bntCancel_Click(object sender, EventArgs e)
    {
        CelarControlAdd();

    }
    
}
